package com.woniu.darryringmall.admin.config;

import com.woniu.darryringmall.admin.service.PermService;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.LinkedHashMap;
import java.util.Map;


public class PermMapFactoryBean implements FactoryBean<Map<String, String>> {
    @Autowired
    private PermService permService;

    @Override
    public Map<String, String> getObject() throws Exception {
        Map<String, String> map = new LinkedHashMap<>();
//        map.put("/admin/manager/login", "anon");
        permService.list().forEach(p -> {
            map.put(p.getLink(), "authc,myPerms[" + p.getCode() + "]");
        });
        map.put("/commentvo", "anon");
        map.put("/commentvo/census", "anon");
        return map;
    }

    @Override
    public Class<?> getObjectType() {
        return Map.class;
    }
}
